﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
/// <summary>
///ComLogin 的摘要说明
/// </summary>
public class ComLogin
{
	public ComLogin()
	{
		//
		//TODO: 在此处添加构造函数逻辑
		//
	}
    private SqlCommand cmd;
    public string LoginCom(string name, string pwd)
    {
        string result = "0";
        try
        {
            cmd = new SqlCommand("select count(*) from tb_company where cpmail=@cpmail and cppwd=@cppwd", ConDB.GetOpen());
            cmd.Parameters.Add("@cpmail", SqlDbType.VarChar).Value = name;
            cmd.Parameters.Add("@cppwd", SqlDbType.VarChar).Value = pwd;
            int x = Convert.ToInt32(cmd.ExecuteScalar());
            if (x > 0)
            {
                result = "1";
            }
        }
        catch (Exception e)
        {
            result = "0";
        }
        finally
        {
            ConDB.Close();
        }
        return result;
    }
    public string isVIP(int id)
    {
        try
        {
            SqlConnection con = ConDB.GetOpen();
            string sql = "select isvip from tb_company where cpid=" + id + "";
            SqlCommand cmd = new SqlCommand(sql, con);
            string str = cmd.ExecuteScalar().ToString();
            if (str=="是")
                return "是";
            else
                return "否";
        }
        catch (SqlException e)
        { return ""; }
        finally
        {
            ConDB.Close();
        }
    }
    public string getMyID(string name, string pwd)
    {
        string result = "";
        try
        {
            cmd = new SqlCommand("select cpid from tb_company where cpmail=@cpmail and cppwd=@cppwd", ConDB.GetOpen());
            cmd.Parameters.Add("@cpmail", SqlDbType.VarChar).Value = name;
            cmd.Parameters.Add("@cppwd", SqlDbType.VarChar).Value = pwd;
            string x = cmd.ExecuteScalar().ToString();
            if (!x.Equals(""))
            {
                result = x;
            }
        }
        catch (Exception e)
        {
            result = "";
        }
        finally
        {
            ConDB.Close();
        }
        return result;
    }
  //  SqlTransaction tran;
   
    public void delCom(int cpid)//删除公司及其关联
    {
     //   Boolean result = true;
        try
        {
            
            cmd = new SqlCommand();
            cmd.Connection = ConDB.GetOpen();
            cmd.CommandText = "delCom";
            cmd.CommandType = CommandType.StoredProcedure;
    //        tran=cmd.Connection.BeginTransaction();
    //        cmd.Transaction = tran;
            cmd.Parameters.Add("@cpid", SqlDbType.Int).Value = cpid;
            cmd.ExecuteNonQuery();
            //if (cmd.ExecuteNonQuery() > 0)
            //{
            //    //             result = false;
            //    //            tran.Commit();
            //}

        }
        catch (Exception e)
        {
   //         result = true;
   //         tran.Rollback();
        }
        finally
        {
            ConDB.Close();
        }
    //    return result;
    }
}
